<template>
	<view class="indexBig">
		<view class="top">
			<!-- <u-icon name="arrow-left" size="36"></u-icon> -->
			<text>当月订单确认</text>
		</view>
		<view class="tableBox" v-if="orderList.length != 0">
			<view class="table">
				<view class="tr">
					<view class="td">菜品</view>
					<view class="td">下单时间</view>
					<view class="td">打卡时间</view>
				</view>
				<view class="tr" v-for="(item, index) in orderList" :key="item.pickingSerialNo">
					<view class="td">
						{{ item.foodsName }}
					</view>
					<view class="td">{{ item.submissionTime }}</view>
					<view class="td">{{ item.dingClockInTime }}</view>
				</view>
			</view>
			<view class="button" @click="confirmOrder" v-if="!hasConfirm">确认本月订单</view>
			<view class="button" v-else>本月订单已确认</view>
		</view>
		<view class="nullBox" v-if="orderList.length == 0">
			<u-empty text="暂无订单数据" mode="page"></u-empty>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getCurrentMonthCompanyOrder,
		confirmCurrentMonthCompanyOrder
	} from '@/utils/req/api.js'
	export default {
		data() {
			return {
				orderList: [],
				params: '',
				hasConfirm: false,

				userId: '',
			}
		},
		onLoad() {
			if (window.location.href.indexOf('userId') != -1) {
				let url = window.location.href;
				let urlList = url.split('?')[1].split('&');
				this.userId = urlList.filter(item => item.indexOf('userId') != -1)[0].split('=')[1]
			}
			let nowDate = new Date();
			let year = nowDate.getFullYear();
			let month = nowDate.getMonth() + 1;
			month = month > 9 ? month : '0' + month
			let fullDate = (year + '-') + month
			this.params = {
				companyId: uni.getStorageSync('companyId'),
				confirmMonth: fullDate,
				userId: this.userId ? this.userId : uni.getStorageSync('myInfo').id
			}
			console.log('params', this.params);
			this._getCurrentMonthCompanyOrder();
		},
		methods: {
			async _getCurrentMonthCompanyOrder() {
				let res = await getCurrentMonthCompanyOrder(this.params);
				console.log('res', res.data.result.list);
				this.orderList = res.data.result.list;
				console.log('this.orderList', this.orderList);
			},
			async confirmOrder() {
				let res = await confirmCurrentMonthCompanyOrder(this.params);
				console.log('res', res);
				if (res.data.success) {
					this.hasConfirm = true;
					this.$showToast.call(this, '本月订单确认成功', 'success');
				} else {
					this.$showToast.call(this, res.data.message, 'warning');
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.indexBig {
		min-height: 100vh;
		background: linear-gradient(0.45deg, #f5f5f5 6.52%, #ff8739 58.65%, #fb690f 98.93%);
		background-size: 100vw 466rpx;
		background-repeat: no-repeat;
		background-color: #f5f5f5;
		padding: 40rpx 20rpx;
		padding-bottom: 150rpx;

		.top {
			position: relative;

			image {
				width: 40rpx;
				height: 40rpx;
				transform: rotate(90deg);
			}

			text {
				width: 100%;
				position: absolute;
				left: 0;
				top: 0;
				text-align: center;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
	}

	.tableBox {
		overflow: hidden;
		overflow-x: scroll;
		background-color: #fff;
		padding: 20rpx 0;
		margin: 40rpx 0;
		background-color: rgba(0, 0, 0, 0);
	}

	.table {
		background-color: rgba(255, 255, 255, 1);
		border-radius: 6rpx;
		overflow: hidden;

		.tr {
			display: flex;
			justify-content: flex-start;
			border: 1px solid #eee;
			border-bottom: 0;

			&:last-child {
				border-bottom: 1px solid #eee;
			}

			&:first-child {
				.td {
					font-weight: bold;
					text-align: center;
				}
			}

			.td {
				padding: 10rpx;
				font-size: 28rpx;
				line-height: 1.5;
				border-bottom: 0;

				&:nth-child(1) {
					flex: 1;
				}

				&:nth-child(2),&:nth-child(3) {
					width: 200rpx;
					flex-shrink: 0;
					text-align: center;
					border-left: 1px solid #eee;
				}
			}
		}
	}

	.nullBox {
		height: 80vh;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 80rpx 0;
		border-radius: 10rpx;
	}

	.button {
		width: calc(100% - 40rpx);
		border-radius: 10rpx;
		font-size: 32rpx;
		color: #fff;
		background-color: #fa690a;
		line-height: 2;
		text-align: center;
		padding: 10rpx 0;
		position: fixed;
		left: 20rpx;
		bottom: 130rpx;
	}
</style>